

import scala.collection.mutable.ArrayBuffer

// 可变类型:scala.collection.mutable.XxxBuffer
object ScalaMutable {
    def main(args: Array[String]): Unit = {
        var element0: String = "element0"
        var element1: String = "element1"
        testArrayBuffer(element0, element1)
    }

    def testArrayBuffer(element0: String, element1: String): Unit = {


        // 变长数组
        var arrayBuffer1 = new ArrayBuffer[String](2)
        arrayBuffer1(0) = "ArrayBuffer0"
        arrayBuffer1(1) = "ArrayBuffer1"

        var arrayBuffer2 = ArrayBuffer(element0, element1)
        // 添加|删除元素
        arrayBuffer1 += element1
        arrayBuffer1 -= element1
        // 追加|移除数组
        arrayBuffer1 ++= arrayBuffer2
        arrayBuffer1 --= arrayBuffer2
    }
}
